//
//  OPQCGuideCell.m
//  NewWorld
//
//  Created by 秦川 on 16/4/27.
//  Copyright © 2016年 itcast. All rights reserved.
//

#import "OPQCGuideCell.h"
#import "Masonry.h"
@interface OPQCGuideCell()
@property(nonatomic,weak)UIImageView *myImageView;
//立即体验
@property(nonatomic,strong)UIButton *mustBtn;
//略过
@property(nonatomic,strong)UIButton *overlookBtn;


@end
@implementation OPQCGuideCell
- (void)scrowWithIndexpath:(NSIndexPath *)indexpath withCount:(NSInteger )count
{
    //判断 最后一个
    if(indexpath.row == count - 1){
        
        self.mustBtn.hidden = NO;
    }else{
        
        self.mustBtn.hidden = YES;
    }
}
- (UIButton *)mustBtn
{
    if (!_mustBtn) {
        
        _mustBtn = [[UIButton alloc]init];
        
        [_mustBtn sizeToFit];

        //监听按钮的点击事件
        [_mustBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        
        [self addSubview:_mustBtn];
    }
    
    return _mustBtn;
}

//跳转到 登陆
- (void)btnClick:(UIButton *)sender
{
    
    //    CZMainTabController *mainVc = [[CZMainTabController alloc]init];
    //
    //    [UIApplication sharedApplication].keyWindow.rootViewController = mainVc;
}
- (void)setGuideImage:(UIImage *)guideImage
{
    _guideImage = guideImage;
    self.myImageView.image = guideImage;
}

//创建一个 带 UIimageVIew的 cell
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        //创建一个 UIiamgeView
        
        UIImageView *imageVIew = [[UIImageView alloc]init];
        
        [self addSubview:imageVIew];
        
        //关联
        self.myImageView = imageVIew;
        UIButton * overlookBtn=[[UIButton alloc]init];
        
        [overlookBtn setTitle:@"略过" forState:UIControlStateNormal];
        overlookBtn.titleLabel.font=[UIFont systemFontOfSize:12];
        [self addSubview:overlookBtn];
        
        self.overlookBtn=overlookBtn;
        [self.overlookBtn addTarget:self action:@selector(overlookBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return self;
}
-(void)overlookBtnClick:(UIButton *)sender{
    //    CZMainTabController *mainVc = [[CZMainTabController alloc]init];
    //
    //    [UIApplication sharedApplication].keyWindow.rootViewController = mainVc;


}
//设置frame
- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.myImageView.frame = self.bounds;
    //设置按钮的frema
//    self.mustBtn.backgroundColor=[UIColor redColor];
    
    [self.overlookBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@40);
        make.height.equalTo(@10);
        make.right.equalTo(self).offset(-10);
        make.top.equalTo(self).offset(35);
    }];
    
    
    //约束设置
    self.mustBtn.translatesAutoresizingMaskIntoConstraints = NO;
    NSLayoutConstraint *buttonBottom = [NSLayoutConstraint constraintWithItem:self.mustBtn attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeBottom multiplier:1 constant:-45];
    
    [self addConstraint:buttonBottom];
    
    NSLayoutConstraint *buttonWidth = [NSLayoutConstraint constraintWithItem:self.mustBtn attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeWidth multiplier:1 constant:220];
    
    [self addConstraint:buttonWidth];
    
    NSLayoutConstraint *buttonHeight = [NSLayoutConstraint constraintWithItem:self.mustBtn attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeHeight multiplier:1 constant:70];
    
    [self addConstraint:buttonHeight];
    
    NSLayoutConstraint *buttonCenterX = [NSLayoutConstraint constraintWithItem:self.mustBtn attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1 constant:([UIScreen mainScreen].bounds.size.width/2-110)];
    
    [self addConstraint:buttonCenterX];

    
    
}

@end
